package com.mystudy.management.usermanagement.service;

import cn.dev33.satoken.stp.StpUtil;
import com.mystudy.management.usermanagement.dao.mappers.AdminMapper;
import com.mystudy.management.usermanagement.dao.mappers.VisitorMapper;
import com.mystudy.management.usermanagement.dao.pojo.Admin;
import com.mystudy.management.usermanagement.dao.pojo.AdminExample;
import com.mystudy.management.usermanagement.dao.pojo.Visitor;
import com.mystudy.management.usermanagement.dao.pojo.VisitorExample;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
//声明事务
@Transactional(
        isolation = Isolation.REPEATABLE_READ//事务隔离级别：可重复读
)
public class LoginServiceImpl implements LoginService {

    private final AdminMapper adminMapper;

    public LoginServiceImpl(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }


    @Override//登录验证
    public boolean messageCheck(Admin admin,boolean remeberChoice) {
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria()
                .andAdminIdEqualTo(admin.getAdminId())
                .andAdminPasswordEqualTo(admin.getAdminPassword());
        List<Admin> getAdmin = adminMapper.selectByExample(adminExample);
        if(getAdmin.size() == 1){
            StpUtil.login(admin.getAdminId(),remeberChoice);//设置Token
            System.out.println(StpUtil.getLoginId());
            return true;
        }
        return false;

    }



}
